import moment from "moment";
import {
  reqLoading,
  req
} from "@/api/req"; //调用接口
export default {
  data() {
    return {
      gridOptions: {
        border: true,
        size: "mini",
        resizable: true,
        showOverflow: true,
        align: "left",
        toolbarConfig: {
          slots: {
            // 自定义工具栏模板
            buttons: "toolbar_buttons"
          }
        }
      },
      tableToolbar: {

      },
    };
  },
  mounted() {

  },
  async created() {

  },

  methods: {
    /**
     * 请求接口
     */
    request(method, url, data, isLoading) {
      let res = []
      if (method == "get") {
        if (isLoading) res = reqLoading(method, url)
        else res = req(method, url)
        return res
      }
      if (method == "post") {
        if (isLoading) res = reqLoading(method, url, data)
        else res = req(method, url, data)
        return res
      }
      if (method == "put") {
        if (isLoading) res = reqLoading(method, url, data)
        else res = req(method, url, data)
        return res
      }
      if (method == "delete") {
        if (isLoading) res = reqLoading(method, url, data)
        else res = req(method, url, data)
        return res
      }
    },

    /**
         * GET URL拼接
         */
    async toGet(url, params) {
      let searchStr = "?";
      for (let val in params) {
        if (params[val] && params[val] != null) {
          searchStr += val + "=" + params[val] + "&";
        }
      }
      if (searchStr[searchStr.length - 1] === "&") {
        searchStr = searchStr.slice(0, searchStr.length - 1);
      }
      return url + searchStr
    },

    /**
     * 弹出框提示消息
     * success/warning/info/error
     */
    resMessage(title, msg, type) {
      this.$alert(msg, "提示", {
        title: title,
        confirmButtonText: "确定",
        type: type
      });
    },
  }
};
